<template>
     <div class="components-container">
         <div class="layui-inline">
            <label class="layui-form-label" >业务编号</label>
             <div class="layui-input-inline">
                <el-input v-model="selectData.RegbussnumLike" placeholder="请输入业务编号"></el-input>
             </div>
        </div>
     
        <div class="layui-inline">
            <label class="layui-form-label" >火化日期</label>
            <!-- RegdateGreaterAndEquals
            RegdateLessAndEquals -->
            <el-date-picker v-date v-model="selectData.RegcremationdateGreaterAndEquals" type="date" placeholder="选择日期范围" >
            </el-date-picker>
             <el-date-picker v-date v-model="selectData.RegcremationdateLessAndEquals" type="date" placeholder="选择日期范围">
            </el-date-picker>
        </div>
        <el-button type="primary" :disabled="downloadLoading" @click="btnSearch"  :loading="this.$store.state.isloading">搜索</el-button>
        <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
        <dataTable :headList="headList" :dataList="dataList" :isIndex="true" :hiddenPageOrder="false" :height="height" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <printmodal ref="printPdf"></printmodal>
         <cresimplereg ref="simpleReg" :orderType="order" @refreshData="getData"></cresimplereg>
     </div>
</template>

<script>
// import { export_json_to_excel } from "@/vendor/Export2Excel.js";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { ORDER } from "@/const/orderConst.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import printmodal from "@/components/Pdf/Print";
import { manage } from "@/mixins/managePage.js";
import cresimplereg from "../businessHall/cresimplereg";
import { PRINT } from "@/components/Pdf/PDF.js";

// import * as Export2Excel from '@/vendor/Export2Excel';


const INFO = "详情";
const EXPORT = "导出";
const CHANGE = "修改";
const COPY = '打印';

export default {
  name: "deadFileSearch",
  mixins: [manage],
  data() {
    return {
      selectData: {
        RegcremationdateGreaterAndEquals: null,
        RegcremationdateLessAndEquals: null,
        RegbussnumLike: null,
      },
      dataLists: [],
      height: "620",
      downloadLoading:false,
      copyLoading:false

    };
  },
  methods: {
    exportExcel() {
      if (this.dataList.length === 0){
          this.$message.error("无导出数据！");
          return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.dataLists, '遗体外运查询');
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.copyLoading = true;
      this.order = order;
      switch (this.order) {
        case INFO:
          this.$refs.simpleReg.open(this.order, this.currentRow.REGID);
          break;
        case EXPORT:
          this.$refs.printPdf.report(PRINT.PDFDEADFILESEARCH, this.getDataC());
          break;
        case CHANGE:
          this.$refs.simpleReg.open(this.order, this.currentRow.REGID);
          break;
        case COPY:
          this.$refs.printPdf.report(PRINT.PDFDEADFILESEARCH, this.getDataC());
          this.copyLoading = false;
          break;
        default:
      }
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetBodyoutageColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取数据
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if(!this.selectData.RegbussnumLike){
        Data.RegbussnumLike = null;
      }
      Data.RegcremationdateGreaterAndEquals = formatDate(
        Data.RegcremationdateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.RegcremationdateLessAndEquals = formatDate(
        Data.RegcremationdateLessAndEquals,
        "yyyyMMdd"
      );
      let data = {
        PageIndex: -1,
        PageSize: 1000,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Search.QuerytTownAshesbox,
        res => {
          this.dataList = res.data.content.OutData;
        //   this.activeName = "results";
        //   this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
  
    btnShow(btn) {
      switch (btn) {
        case "导出":
          return true;
          break;
        case "修改":
          return true;
          break;
        case "打印":
          return true;
        break; 
        default:
          return false;
      }
    },
    //搜索按钮
    btnSearch(){
      this.getData();
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        RegcremationdateGreaterAndEquals: null,
        RegcremationdateLessAndEquals: null,
        RegbussnumLike: null,
      };
      this.RegHouseholeEquals = [];
      this.selectData.RegcremationdateGreaterAndEquals = new Date();
      this.selectData.RegcremationdateGreaterAndEquals.setDate(1);
      this.selectData.RegcremationdateLessAndEquals = new Date();
      var day = new Date();
      var year = day.getFullYear();
      var month = day.getMonth() + 1;
      var d = new Date(year, month, 0);
      var dat = d.getDate();
      this.selectData.RegcremationdateLessAndEquals.setDate(dat);
      this.getData();
    }
  },
  mounted() {},
  components: {
    dataTable,
    cresimplereg,
    printmodal
  },
  created() {
    this.selectData.RegcremationdateGreaterAndEquals = new Date();
    this.selectData.RegcremationdateGreaterAndEquals.setDate(1);
    this.selectData.RegcremationdateLessAndEquals = new Date();
    var day = new Date();
    var year = day.getFullYear();
    var month = day.getMonth() + 1;
    var d = new Date(year, month, 0);
    var dat = d.getDate();
    this.selectData.RegcremationdateLessAndEquals.setDate(dat);
    this.getColumns();
    this.getData();
  }
};
</script>

